/**
 * Created by lance on 2017/2/27.
 */
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { Jsonp, URLSearchParams,Response } from '@angular/http';
import { Observable }   from 'rxjs/observable';
import 'rxjs/add/operator/catch';

@Injectable()
export class ResService {
  constructor(private jsonp: Jsonp) {}

  resdet (productid:string) {
    let resdetail = 'http://api.pinwu.net/site/prodetail';
    let params = new URLSearchParams();
    params.set('productid', productid);                 // the user's repwd
    params.set('callback', 'JSONP_CALLBACK');

    return this.jsonp
      .get(resdetail, { search: params })
      .map((res:Response)=>{
        let result=res.json();
        console.log(result);
        return result;
      });
  }
  collectlist () {
    let resdetaillist = 'http://api.pinwu.net/site/persional';
    let params = new URLSearchParams();
    params.set('callback', 'JSONP_CALLBACK');

    return this.jsonp
      .get(resdetaillist, { search: params })
      .map((res:Response)=>{
        let result=res.json();
        console.log(result);
        return result;
      });
  }
  addcollect(collect_id:string,product_id:string){
    let addlink='http://api.pinwu.net/site/addtobox';
    let params = new URLSearchParams();
    params.set('product_id', product_id);
    params.set('collect_id', collect_id);
    params.set('callback', 'JSONP_CALLBACK');
    return this.jsonp
      .get(addlink, { search: params })
      .map((res:Response)=>{
        let result=res.json();
        console.log(result);
        return result;
      });
  }
}
